﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace QLNHK.BLL
{
	public partial class DoiTuong : Ent_Base, ICloneable
	{
        #region Variables
        
		private long _iD;
		private string _hoLot = string.Empty;
		private string _ten = string.Empty;
		private string _tenGoiKhac = string.Empty;
		private int _gioiTinh;
		private int _ngaySinh;
		private int _thangSinh;
		private int _namSinh;
		private string _noiSinh = string.Empty;
		private int _queQuanTinhTPID;
		private int _queQuanQuanHuyenID;
		private int _queQuanXaPhuongID;
		private int _queQuanToID;
		private int _danTocID;
		private int _quocTichID;
		private int _tonGiaoID;
		private string _soCMND = string.Empty;
		private DateTime _ngayCapCMND = new DateTime(1753, 1, 1);
		private string _noiCapCMND = string.Empty;
		private int _thuongTruTinhTPID;
		private int _thuongTruQuanHuyenID;
		private int _thuongTruXaPhuongID;
		private int _thuongTruToID;
		private string _thuongTruDiaChi = string.Empty;
		private int _noiOHienNayTinhTPID;
		private int _noiOHienNayQuanHuyenID;
		private int _noiOHienNayXaPhuongID;
		private int _noiOHienNayToID;
		private string _noiOHienNayDiaChi = string.Empty;
		private int _trinhDoHocVanID;
		private int _trinhDoChuyenMonID;
		private string _ngheNghiepNoiLamViec = string.Empty;
		private string _soDienThoaiLienHe = string.Empty;
		private string _maDoiTuong = string.Empty;
		private string _hoTenBo = string.Empty;
		private int _namSinhBo;
		private string _hoTenMe = string.Empty;
		private int _namSinhMe;
		private string _hoTenVoChong = string.Empty;
		private int _namSinhVoChong;
		private string _cao = string.Empty;
		private string _songMui = string.Empty;
		private string _tamVoc = string.Empty;
		private string _giongNoi = string.Empty;
		private string _nepTai = string.Empty;
		private string _daiTai = string.Empty;
		private string _mauDa = string.Empty;
		private string _dauVet = string.Empty;
		private bool _isDelete;
		private int _canBoQuanLyID;
		private string _maNhanKhau = string.Empty;
		private string _quanHeCanChuY = string.Empty;
        
        #endregion
    
        //---------------------------------------------------------------------------------------------
        
		#region Properties.
		
		public long ID 
        { 
            get { return  _iD; } 
            set
            {
                _iD = value;
                OnPropertyChanged("ID");
            }
        }
		public string HoLot 
        { 
            get { return  _hoLot; } 
            set
            {
                _hoLot = value;
                OnPropertyChanged("HoLot");
            }
        }
		public string Ten 
        { 
            get { return  _ten; } 
            set
            {
                _ten = value;
                OnPropertyChanged("Ten");
            }
        }
		public string TenGoiKhac 
        { 
            get { return  _tenGoiKhac; } 
            set
            {
                _tenGoiKhac = value;
                OnPropertyChanged("TenGoiKhac");
            }
        }
		public int GioiTinh 
        { 
            get { return  _gioiTinh; } 
            set
            {
                _gioiTinh = value;
                OnPropertyChanged("GioiTinh");
            }
        }
		public int NgaySinh 
        { 
            get { return  _ngaySinh; } 
            set
            {
                _ngaySinh = value;
                OnPropertyChanged("NgaySinh");
            }
        }
		public int ThangSinh 
        { 
            get { return  _thangSinh; } 
            set
            {
                _thangSinh = value;
                OnPropertyChanged("ThangSinh");
            }
        }
		public int NamSinh 
        { 
            get { return  _namSinh; } 
            set
            {
                _namSinh = value;
                OnPropertyChanged("NamSinh");
            }
        }
		public string NoiSinh 
        { 
            get { return  _noiSinh; } 
            set
            {
                _noiSinh = value;
                OnPropertyChanged("NoiSinh");
            }
        }
		public int QueQuanTinhTPID 
        { 
            get { return  _queQuanTinhTPID; } 
            set
            {
                _queQuanTinhTPID = value;
                OnPropertyChanged("QueQuanTinhTPID");
            }
        }
		public int QueQuanQuanHuyenID 
        { 
            get { return  _queQuanQuanHuyenID; } 
            set
            {
                _queQuanQuanHuyenID = value;
                OnPropertyChanged("QueQuanQuanHuyenID");
            }
        }
		public int QueQuanXaPhuongID 
        { 
            get { return  _queQuanXaPhuongID; } 
            set
            {
                _queQuanXaPhuongID = value;
                OnPropertyChanged("QueQuanXaPhuongID");
            }
        }
		public int QueQuanToID 
        { 
            get { return  _queQuanToID; } 
            set
            {
                _queQuanToID = value;
                OnPropertyChanged("QueQuanToID");
            }
        }
		public int DanTocID 
        { 
            get { return  _danTocID; } 
            set
            {
                _danTocID = value;
                OnPropertyChanged("DanTocID");
            }
        }
		public int QuocTichID 
        { 
            get { return  _quocTichID; } 
            set
            {
                _quocTichID = value;
                OnPropertyChanged("QuocTichID");
            }
        }
		public int TonGiaoID 
        { 
            get { return  _tonGiaoID; } 
            set
            {
                _tonGiaoID = value;
                OnPropertyChanged("TonGiaoID");
            }
        }
		public string SoCMND 
        { 
            get { return  _soCMND; } 
            set
            {
                _soCMND = value;
                OnPropertyChanged("SoCMND");
            }
        }
		public DateTime NgayCapCMND 
        { 
            get { return  _ngayCapCMND; } 
            set
            {
                _ngayCapCMND = value;
                OnPropertyChanged("NgayCapCMND");
            }
        }
		public string NoiCapCMND 
        { 
            get { return  _noiCapCMND; } 
            set
            {
                _noiCapCMND = value;
                OnPropertyChanged("NoiCapCMND");
            }
        }
		public int ThuongTruTinhTPID 
        { 
            get { return  _thuongTruTinhTPID; } 
            set
            {
                _thuongTruTinhTPID = value;
                OnPropertyChanged("ThuongTruTinhTPID");
            }
        }
		public int ThuongTruQuanHuyenID 
        { 
            get { return  _thuongTruQuanHuyenID; } 
            set
            {
                _thuongTruQuanHuyenID = value;
                OnPropertyChanged("ThuongTruQuanHuyenID");
            }
        }
		public int ThuongTruXaPhuongID 
        { 
            get { return  _thuongTruXaPhuongID; } 
            set
            {
                _thuongTruXaPhuongID = value;
                OnPropertyChanged("ThuongTruXaPhuongID");
            }
        }
		public int ThuongTruToID 
        { 
            get { return  _thuongTruToID; } 
            set
            {
                _thuongTruToID = value;
                OnPropertyChanged("ThuongTruToID");
            }
        }
		public string ThuongTruDiaChi 
        { 
            get { return  _thuongTruDiaChi; } 
            set
            {
                _thuongTruDiaChi = value;
                OnPropertyChanged("ThuongTruDiaChi");
            }
        }
		public int NoiOHienNayTinhTPID 
        { 
            get { return  _noiOHienNayTinhTPID; } 
            set
            {
                _noiOHienNayTinhTPID = value;
                OnPropertyChanged("NoiOHienNayTinhTPID");
            }
        }
		public int NoiOHienNayQuanHuyenID 
        { 
            get { return  _noiOHienNayQuanHuyenID; } 
            set
            {
                _noiOHienNayQuanHuyenID = value;
                OnPropertyChanged("NoiOHienNayQuanHuyenID");
            }
        }
		public int NoiOHienNayXaPhuongID 
        { 
            get { return  _noiOHienNayXaPhuongID; } 
            set
            {
                _noiOHienNayXaPhuongID = value;
                OnPropertyChanged("NoiOHienNayXaPhuongID");
            }
        }
		public int NoiOHienNayToID 
        { 
            get { return  _noiOHienNayToID; } 
            set
            {
                _noiOHienNayToID = value;
                OnPropertyChanged("NoiOHienNayToID");
            }
        }
		public string NoiOHienNayDiaChi 
        { 
            get { return  _noiOHienNayDiaChi; } 
            set
            {
                _noiOHienNayDiaChi = value;
                OnPropertyChanged("NoiOHienNayDiaChi");
            }
        }
		public int TrinhDoHocVanID 
        { 
            get { return  _trinhDoHocVanID; } 
            set
            {
                _trinhDoHocVanID = value;
                OnPropertyChanged("TrinhDoHocVanID");
            }
        }
		public int TrinhDoChuyenMonID 
        { 
            get { return  _trinhDoChuyenMonID; } 
            set
            {
                _trinhDoChuyenMonID = value;
                OnPropertyChanged("TrinhDoChuyenMonID");
            }
        }
		public string NgheNghiepNoiLamViec 
        { 
            get { return  _ngheNghiepNoiLamViec; } 
            set
            {
                _ngheNghiepNoiLamViec = value;
                OnPropertyChanged("NgheNghiepNoiLamViec");
            }
        }
		public string SoDienThoaiLienHe 
        { 
            get { return  _soDienThoaiLienHe; } 
            set
            {
                _soDienThoaiLienHe = value;
                OnPropertyChanged("SoDienThoaiLienHe");
            }
        }
		public string MaDoiTuong 
        { 
            get { return  _maDoiTuong; } 
            set
            {
                _maDoiTuong = value;
                OnPropertyChanged("MaDoiTuong");
            }
        }
		public string HoTenBo 
        { 
            get { return  _hoTenBo; } 
            set
            {
                _hoTenBo = value;
                OnPropertyChanged("HoTenBo");
            }
        }
		public int NamSinhBo 
        { 
            get { return  _namSinhBo; } 
            set
            {
                _namSinhBo = value;
                OnPropertyChanged("NamSinhBo");
            }
        }
		public string HoTenMe 
        { 
            get { return  _hoTenMe; } 
            set
            {
                _hoTenMe = value;
                OnPropertyChanged("HoTenMe");
            }
        }
		public int NamSinhMe 
        { 
            get { return  _namSinhMe; } 
            set
            {
                _namSinhMe = value;
                OnPropertyChanged("NamSinhMe");
            }
        }
		public string HoTenVoChong 
        { 
            get { return  _hoTenVoChong; } 
            set
            {
                _hoTenVoChong = value;
                OnPropertyChanged("HoTenVoChong");
            }
        }
		public int NamSinhVoChong 
        { 
            get { return  _namSinhVoChong; } 
            set
            {
                _namSinhVoChong = value;
                OnPropertyChanged("NamSinhVoChong");
            }
        }
		public string Cao 
        { 
            get { return  _cao; } 
            set
            {
                _cao = value;
                OnPropertyChanged("Cao");
            }
        }
		public string SongMui 
        { 
            get { return  _songMui; } 
            set
            {
                _songMui = value;
                OnPropertyChanged("SongMui");
            }
        }
		public string TamVoc 
        { 
            get { return  _tamVoc; } 
            set
            {
                _tamVoc = value;
                OnPropertyChanged("TamVoc");
            }
        }
		public string GiongNoi 
        { 
            get { return  _giongNoi; } 
            set
            {
                _giongNoi = value;
                OnPropertyChanged("GiongNoi");
            }
        }
		public string NepTai 
        { 
            get { return  _nepTai; } 
            set
            {
                _nepTai = value;
                OnPropertyChanged("NepTai");
            }
        }
		public string DaiTai 
        { 
            get { return  _daiTai; } 
            set
            {
                _daiTai = value;
                OnPropertyChanged("DaiTai");
            }
        }
		public string MauDa 
        { 
            get { return  _mauDa; } 
            set
            {
                _mauDa = value;
                OnPropertyChanged("MauDa");
            }
        }
		public string DauVet 
        { 
            get { return  _dauVet; } 
            set
            {
                _dauVet = value;
                OnPropertyChanged("DauVet");
            }
        }
		public bool IsDelete 
        { 
            get { return  _isDelete; } 
            set
            {
                _isDelete = value;
                OnPropertyChanged("IsDelete");
            }
        }
		public int CanBoQuanLyID 
        { 
            get { return  _canBoQuanLyID; } 
            set
            {
                _canBoQuanLyID = value;
                OnPropertyChanged("CanBoQuanLyID");
            }
        }
		public string MaNhanKhau 
        { 
            get { return  _maNhanKhau; } 
            set
            {
                _maNhanKhau = value;
                OnPropertyChanged("MaNhanKhau");
            }
        }
		public string QuanHeCanChuY 
        { 
            get { return  _quanHeCanChuY; } 
            set
            {
                _quanHeCanChuY = value;
                OnPropertyChanged("QuanHeCanChuY");
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Methods
		protected static List<DoiTuong> ConvertToCollection(IDataReader reader)
		{
			List<DoiTuong> collection = new List<DoiTuong>();
			while (reader.Read())
			{
				DoiTuong entity = new DoiTuong();
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt64(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoLot"))) entity.HoLot = reader.GetString(reader.GetOrdinal("HoLot"));
				if (!reader.IsDBNull(reader.GetOrdinal("Ten"))) entity.Ten = reader.GetString(reader.GetOrdinal("Ten"));
				if (!reader.IsDBNull(reader.GetOrdinal("TenGoiKhac"))) entity.TenGoiKhac = reader.GetString(reader.GetOrdinal("TenGoiKhac"));
				if (!reader.IsDBNull(reader.GetOrdinal("GioiTinh"))) entity.GioiTinh = reader.GetInt32(reader.GetOrdinal("GioiTinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgaySinh"))) entity.NgaySinh = reader.GetInt32(reader.GetOrdinal("NgaySinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThangSinh"))) entity.ThangSinh = reader.GetInt32(reader.GetOrdinal("ThangSinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamSinh"))) entity.NamSinh = reader.GetInt32(reader.GetOrdinal("NamSinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiSinh"))) entity.NoiSinh = reader.GetString(reader.GetOrdinal("NoiSinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanTinhTPID"))) entity.QueQuanTinhTPID = reader.GetInt32(reader.GetOrdinal("QueQuanTinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanQuanHuyenID"))) entity.QueQuanQuanHuyenID = reader.GetInt32(reader.GetOrdinal("QueQuanQuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanXaPhuongID"))) entity.QueQuanXaPhuongID = reader.GetInt32(reader.GetOrdinal("QueQuanXaPhuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanToID"))) entity.QueQuanToID = reader.GetInt32(reader.GetOrdinal("QueQuanToID"));
				if (!reader.IsDBNull(reader.GetOrdinal("DanTocID"))) entity.DanTocID = reader.GetInt32(reader.GetOrdinal("DanTocID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QuocTichID"))) entity.QuocTichID = reader.GetInt32(reader.GetOrdinal("QuocTichID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TonGiaoID"))) entity.TonGiaoID = reader.GetInt32(reader.GetOrdinal("TonGiaoID"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoCMND"))) entity.SoCMND = reader.GetString(reader.GetOrdinal("SoCMND"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayCapCMND"))) entity.NgayCapCMND = reader.GetDateTime(reader.GetOrdinal("NgayCapCMND"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiCapCMND"))) entity.NoiCapCMND = reader.GetString(reader.GetOrdinal("NoiCapCMND"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruTinhTPID"))) entity.ThuongTruTinhTPID = reader.GetInt32(reader.GetOrdinal("ThuongTruTinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruQuanHuyenID"))) entity.ThuongTruQuanHuyenID = reader.GetInt32(reader.GetOrdinal("ThuongTruQuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruXaPhuongID"))) entity.ThuongTruXaPhuongID = reader.GetInt32(reader.GetOrdinal("ThuongTruXaPhuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruToID"))) entity.ThuongTruToID = reader.GetInt32(reader.GetOrdinal("ThuongTruToID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruDiaChi"))) entity.ThuongTruDiaChi = reader.GetString(reader.GetOrdinal("ThuongTruDiaChi"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayTinhTPID"))) entity.NoiOHienNayTinhTPID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayTinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayQuanHuyenID"))) entity.NoiOHienNayQuanHuyenID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayQuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayXaPhuongID"))) entity.NoiOHienNayXaPhuongID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayXaPhuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayToID"))) entity.NoiOHienNayToID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayToID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayDiaChi"))) entity.NoiOHienNayDiaChi = reader.GetString(reader.GetOrdinal("NoiOHienNayDiaChi"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrinhDoHocVanID"))) entity.TrinhDoHocVanID = reader.GetInt32(reader.GetOrdinal("TrinhDoHocVanID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrinhDoChuyenMonID"))) entity.TrinhDoChuyenMonID = reader.GetInt32(reader.GetOrdinal("TrinhDoChuyenMonID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgheNghiepNoiLamViec"))) entity.NgheNghiepNoiLamViec = reader.GetString(reader.GetOrdinal("NgheNghiepNoiLamViec"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoDienThoaiLienHe"))) entity.SoDienThoaiLienHe = reader.GetString(reader.GetOrdinal("SoDienThoaiLienHe"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaDoiTuong"))) entity.MaDoiTuong = reader.GetString(reader.GetOrdinal("MaDoiTuong"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoTenBo"))) entity.HoTenBo = reader.GetString(reader.GetOrdinal("HoTenBo"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamSinhBo"))) entity.NamSinhBo = reader.GetInt32(reader.GetOrdinal("NamSinhBo"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoTenMe"))) entity.HoTenMe = reader.GetString(reader.GetOrdinal("HoTenMe"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamSinhMe"))) entity.NamSinhMe = reader.GetInt32(reader.GetOrdinal("NamSinhMe"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoTenVoChong"))) entity.HoTenVoChong = reader.GetString(reader.GetOrdinal("HoTenVoChong"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamSinhVoChong"))) entity.NamSinhVoChong = reader.GetInt32(reader.GetOrdinal("NamSinhVoChong"));
				if (!reader.IsDBNull(reader.GetOrdinal("Cao"))) entity.Cao = reader.GetString(reader.GetOrdinal("Cao"));
				if (!reader.IsDBNull(reader.GetOrdinal("SongMui"))) entity.SongMui = reader.GetString(reader.GetOrdinal("SongMui"));
				if (!reader.IsDBNull(reader.GetOrdinal("TamVoc"))) entity.TamVoc = reader.GetString(reader.GetOrdinal("TamVoc"));
				if (!reader.IsDBNull(reader.GetOrdinal("GiongNoi"))) entity.GiongNoi = reader.GetString(reader.GetOrdinal("GiongNoi"));
				if (!reader.IsDBNull(reader.GetOrdinal("NepTai"))) entity.NepTai = reader.GetString(reader.GetOrdinal("NepTai"));
				if (!reader.IsDBNull(reader.GetOrdinal("DaiTai"))) entity.DaiTai = reader.GetString(reader.GetOrdinal("DaiTai"));
				if (!reader.IsDBNull(reader.GetOrdinal("MauDa"))) entity.MauDa = reader.GetString(reader.GetOrdinal("MauDa"));
				if (!reader.IsDBNull(reader.GetOrdinal("DauVet"))) entity.DauVet = reader.GetString(reader.GetOrdinal("DauVet"));
				if (!reader.IsDBNull(reader.GetOrdinal("IsDelete"))) entity.IsDelete = reader.GetBoolean(reader.GetOrdinal("IsDelete"));
				if (!reader.IsDBNull(reader.GetOrdinal("CanBoQuanLyID"))) entity.CanBoQuanLyID = reader.GetInt32(reader.GetOrdinal("CanBoQuanLyID"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaNhanKhau"))) entity.MaNhanKhau = reader.GetString(reader.GetOrdinal("MaNhanKhau"));
				if (!reader.IsDBNull(reader.GetOrdinal("QuanHeCanChuY"))) entity.QuanHeCanChuY = reader.GetString(reader.GetOrdinal("QuanHeCanChuY"));
				collection.Add(entity);
			}
			reader.Close();
			return collection;
		}
		
		public static bool Find(List<DoiTuong> collection, long iD)
        {
            foreach (DoiTuong item in collection)
            {
                if (item.ID == iD)
                {
                    return true;
                }
            }

            return false;
        }
		
		public static void UpdateDataSet(DataSet ds)
        {
            string insert = "Insert INTO t_DoiTuong VALUES(@HoLot, @Ten, @TenGoiKhac, @GioiTinh, @NgaySinh, @ThangSinh, @NamSinh, @NoiSinh, @QueQuanTinhTPID, @QueQuanQuanHuyenID, @QueQuanXaPhuongID, @QueQuanToID, @DanTocID, @QuocTichID, @TonGiaoID, @SoCMND, @NgayCapCMND, @NoiCapCMND, @ThuongTruTinhTPID, @ThuongTruQuanHuyenID, @ThuongTruXaPhuongID, @ThuongTruToID, @ThuongTruDiaChi, @NoiOHienNayTinhTPID, @NoiOHienNayQuanHuyenID, @NoiOHienNayXaPhuongID, @NoiOHienNayToID, @NoiOHienNayDiaChi, @TrinhDoHocVanID, @TrinhDoChuyenMonID, @NgheNghiepNoiLamViec, @SoDienThoaiLienHe, @MaDoiTuong, @HoTenBo, @NamSinhBo, @HoTenMe, @NamSinhMe, @HoTenVoChong, @NamSinhVoChong, @Cao, @SongMui, @TamVoc, @GiongNoi, @NepTai, @DaiTai, @MauDa, @DauVet, @IsDelete, @CanBoQuanLyID, @MaNhanKhau, @QuanHeCanChuY)";
            string update = "UPDATE t_DoiTuong SET HoLot = @HoLot, Ten = @Ten, TenGoiKhac = @TenGoiKhac, GioiTinh = @GioiTinh, NgaySinh = @NgaySinh, ThangSinh = @ThangSinh, NamSinh = @NamSinh, NoiSinh = @NoiSinh, QueQuanTinhTPID = @QueQuanTinhTPID, QueQuanQuanHuyenID = @QueQuanQuanHuyenID, QueQuanXaPhuongID = @QueQuanXaPhuongID, QueQuanToID = @QueQuanToID, DanTocID = @DanTocID, QuocTichID = @QuocTichID, TonGiaoID = @TonGiaoID, SoCMND = @SoCMND, NgayCapCMND = @NgayCapCMND, NoiCapCMND = @NoiCapCMND, ThuongTruTinhTPID = @ThuongTruTinhTPID, ThuongTruQuanHuyenID = @ThuongTruQuanHuyenID, ThuongTruXaPhuongID = @ThuongTruXaPhuongID, ThuongTruToID = @ThuongTruToID, ThuongTruDiaChi = @ThuongTruDiaChi, NoiOHienNayTinhTPID = @NoiOHienNayTinhTPID, NoiOHienNayQuanHuyenID = @NoiOHienNayQuanHuyenID, NoiOHienNayXaPhuongID = @NoiOHienNayXaPhuongID, NoiOHienNayToID = @NoiOHienNayToID, NoiOHienNayDiaChi = @NoiOHienNayDiaChi, TrinhDoHocVanID = @TrinhDoHocVanID, TrinhDoChuyenMonID = @TrinhDoChuyenMonID, NgheNghiepNoiLamViec = @NgheNghiepNoiLamViec, SoDienThoaiLienHe = @SoDienThoaiLienHe, MaDoiTuong = @MaDoiTuong, HoTenBo = @HoTenBo, NamSinhBo = @NamSinhBo, HoTenMe = @HoTenMe, NamSinhMe = @NamSinhMe, HoTenVoChong = @HoTenVoChong, NamSinhVoChong = @NamSinhVoChong, Cao = @Cao, SongMui = @SongMui, TamVoc = @TamVoc, GiongNoi = @GiongNoi, NepTai = @NepTai, DaiTai = @DaiTai, MauDa = @MauDa, DauVet = @DauVet, IsDelete = @IsDelete, CanBoQuanLyID = @CanBoQuanLyID, MaNhanKhau = @MaNhanKhau, QuanHeCanChuY = @QuanHeCanChuY WHERE ID = @ID";
            string delete = "DELETE FROM t_DoiTuong WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MaDoiTuong", SqlDbType.VarChar, "MaDoiTuong", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoTenBo", SqlDbType.NVarChar, "HoTenBo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinhBo", SqlDbType.Int, "NamSinhBo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoTenMe", SqlDbType.NVarChar, "HoTenMe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinhMe", SqlDbType.Int, "NamSinhMe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoTenVoChong", SqlDbType.NVarChar, "HoTenVoChong", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinhVoChong", SqlDbType.Int, "NamSinhVoChong", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@Cao", SqlDbType.NVarChar, "Cao", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SongMui", SqlDbType.NVarChar, "SongMui", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TamVoc", SqlDbType.NVarChar, "TamVoc", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GiongNoi", SqlDbType.NVarChar, "GiongNoi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NepTai", SqlDbType.NVarChar, "NepTai", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DaiTai", SqlDbType.NVarChar, "DaiTai", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MauDa", SqlDbType.NVarChar, "MauDa", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DauVet", SqlDbType.NVarChar, "DauVet", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MaNhanKhau", SqlDbType.NVarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, "QuanHeCanChuY", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MaDoiTuong", SqlDbType.VarChar, "MaDoiTuong", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoTenBo", SqlDbType.NVarChar, "HoTenBo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinhBo", SqlDbType.Int, "NamSinhBo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoTenMe", SqlDbType.NVarChar, "HoTenMe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinhMe", SqlDbType.Int, "NamSinhMe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoTenVoChong", SqlDbType.NVarChar, "HoTenVoChong", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinhVoChong", SqlDbType.Int, "NamSinhVoChong", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@Cao", SqlDbType.NVarChar, "Cao", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SongMui", SqlDbType.NVarChar, "SongMui", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TamVoc", SqlDbType.NVarChar, "TamVoc", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GiongNoi", SqlDbType.NVarChar, "GiongNoi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NepTai", SqlDbType.NVarChar, "NepTai", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DaiTai", SqlDbType.NVarChar, "DaiTai", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MauDa", SqlDbType.NVarChar, "MauDa", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DauVet", SqlDbType.NVarChar, "DauVet", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MaNhanKhau", SqlDbType.NVarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, "QuanHeCanChuY", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, ds.Tables[0].TableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }
				
		public static void UpdateDataSet(DataSet ds, string tableName)
        {
            string insert = "Insert INTO t_DoiTuong VALUES(@HoLot, @Ten, @TenGoiKhac, @GioiTinh, @NgaySinh, @ThangSinh, @NamSinh, @NoiSinh, @QueQuanTinhTPID, @QueQuanQuanHuyenID, @QueQuanXaPhuongID, @QueQuanToID, @DanTocID, @QuocTichID, @TonGiaoID, @SoCMND, @NgayCapCMND, @NoiCapCMND, @ThuongTruTinhTPID, @ThuongTruQuanHuyenID, @ThuongTruXaPhuongID, @ThuongTruToID, @ThuongTruDiaChi, @NoiOHienNayTinhTPID, @NoiOHienNayQuanHuyenID, @NoiOHienNayXaPhuongID, @NoiOHienNayToID, @NoiOHienNayDiaChi, @TrinhDoHocVanID, @TrinhDoChuyenMonID, @NgheNghiepNoiLamViec, @SoDienThoaiLienHe, @MaDoiTuong, @HoTenBo, @NamSinhBo, @HoTenMe, @NamSinhMe, @HoTenVoChong, @NamSinhVoChong, @Cao, @SongMui, @TamVoc, @GiongNoi, @NepTai, @DaiTai, @MauDa, @DauVet, @IsDelete, @CanBoQuanLyID, @MaNhanKhau, @QuanHeCanChuY)";
            string update = "UPDATE t_DoiTuong SET HoLot = @HoLot, Ten = @Ten, TenGoiKhac = @TenGoiKhac, GioiTinh = @GioiTinh, NgaySinh = @NgaySinh, ThangSinh = @ThangSinh, NamSinh = @NamSinh, NoiSinh = @NoiSinh, QueQuanTinhTPID = @QueQuanTinhTPID, QueQuanQuanHuyenID = @QueQuanQuanHuyenID, QueQuanXaPhuongID = @QueQuanXaPhuongID, QueQuanToID = @QueQuanToID, DanTocID = @DanTocID, QuocTichID = @QuocTichID, TonGiaoID = @TonGiaoID, SoCMND = @SoCMND, NgayCapCMND = @NgayCapCMND, NoiCapCMND = @NoiCapCMND, ThuongTruTinhTPID = @ThuongTruTinhTPID, ThuongTruQuanHuyenID = @ThuongTruQuanHuyenID, ThuongTruXaPhuongID = @ThuongTruXaPhuongID, ThuongTruToID = @ThuongTruToID, ThuongTruDiaChi = @ThuongTruDiaChi, NoiOHienNayTinhTPID = @NoiOHienNayTinhTPID, NoiOHienNayQuanHuyenID = @NoiOHienNayQuanHuyenID, NoiOHienNayXaPhuongID = @NoiOHienNayXaPhuongID, NoiOHienNayToID = @NoiOHienNayToID, NoiOHienNayDiaChi = @NoiOHienNayDiaChi, TrinhDoHocVanID = @TrinhDoHocVanID, TrinhDoChuyenMonID = @TrinhDoChuyenMonID, NgheNghiepNoiLamViec = @NgheNghiepNoiLamViec, SoDienThoaiLienHe = @SoDienThoaiLienHe, MaDoiTuong = @MaDoiTuong, HoTenBo = @HoTenBo, NamSinhBo = @NamSinhBo, HoTenMe = @HoTenMe, NamSinhMe = @NamSinhMe, HoTenVoChong = @HoTenVoChong, NamSinhVoChong = @NamSinhVoChong, Cao = @Cao, SongMui = @SongMui, TamVoc = @TamVoc, GiongNoi = @GiongNoi, NepTai = @NepTai, DaiTai = @DaiTai, MauDa = @MauDa, DauVet = @DauVet, IsDelete = @IsDelete, CanBoQuanLyID = @CanBoQuanLyID, MaNhanKhau = @MaNhanKhau, QuanHeCanChuY = @QuanHeCanChuY WHERE ID = @ID";
            string delete = "DELETE FROM t_DoiTuong WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MaDoiTuong", SqlDbType.VarChar, "MaDoiTuong", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoTenBo", SqlDbType.NVarChar, "HoTenBo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinhBo", SqlDbType.Int, "NamSinhBo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoTenMe", SqlDbType.NVarChar, "HoTenMe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinhMe", SqlDbType.Int, "NamSinhMe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoTenVoChong", SqlDbType.NVarChar, "HoTenVoChong", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinhVoChong", SqlDbType.Int, "NamSinhVoChong", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@Cao", SqlDbType.NVarChar, "Cao", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SongMui", SqlDbType.NVarChar, "SongMui", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TamVoc", SqlDbType.NVarChar, "TamVoc", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GiongNoi", SqlDbType.NVarChar, "GiongNoi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NepTai", SqlDbType.NVarChar, "NepTai", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DaiTai", SqlDbType.NVarChar, "DaiTai", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MauDa", SqlDbType.NVarChar, "MauDa", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DauVet", SqlDbType.NVarChar, "DauVet", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MaNhanKhau", SqlDbType.NVarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, "QuanHeCanChuY", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MaDoiTuong", SqlDbType.VarChar, "MaDoiTuong", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoTenBo", SqlDbType.NVarChar, "HoTenBo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinhBo", SqlDbType.Int, "NamSinhBo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoTenMe", SqlDbType.NVarChar, "HoTenMe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinhMe", SqlDbType.Int, "NamSinhMe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoTenVoChong", SqlDbType.NVarChar, "HoTenVoChong", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinhVoChong", SqlDbType.Int, "NamSinhVoChong", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@Cao", SqlDbType.NVarChar, "Cao", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SongMui", SqlDbType.NVarChar, "SongMui", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TamVoc", SqlDbType.NVarChar, "TamVoc", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GiongNoi", SqlDbType.NVarChar, "GiongNoi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NepTai", SqlDbType.NVarChar, "NepTai", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DaiTai", SqlDbType.NVarChar, "DaiTai", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MauDa", SqlDbType.NVarChar, "MauDa", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DauVet", SqlDbType.NVarChar, "DauVet", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MaNhanKhau", SqlDbType.NVarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, "QuanHeCanChuY", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, tableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }

		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static DoiTuong Load(long iD)
		{
			const string spName = "[dbo].[p_DoiTuong_Load.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, iD);
            IDataReader reader = db.ExecuteReader(dbCommand);
			List<DoiTuong> collection = ConvertToCollection(reader);	
			if (collection.Count > 0)
			{
				return collection[0];
			}
			return null;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static List<DoiTuong> SelectCollectionAll()
		{
			IDataReader reader = SelectReaderAll();
			return ConvertToCollection(reader);			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static List<DoiTuong> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			IDataReader reader = SelectReaderDynamic(whereCondition, orderByExpression);
			return ConvertToCollection(reader);		
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_DoiTuong_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_DoiTuong_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_DoiTuong_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_DoiTuong_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static long InsertDoiTuong(string hoLot, string ten, string tenGoiKhac, int gioiTinh, int ngaySinh, int thangSinh, int namSinh, string noiSinh, int queQuanTinhTPID, int queQuanQuanHuyenID, int queQuanXaPhuongID, int queQuanToID, int danTocID, int quocTichID, int tonGiaoID, string soCMND, DateTime ngayCapCMND, string noiCapCMND, int thuongTruTinhTPID, int thuongTruQuanHuyenID, int thuongTruXaPhuongID, int thuongTruToID, string thuongTruDiaChi, int noiOHienNayTinhTPID, int noiOHienNayQuanHuyenID, int noiOHienNayXaPhuongID, int noiOHienNayToID, string noiOHienNayDiaChi, int trinhDoHocVanID, int trinhDoChuyenMonID, string ngheNghiepNoiLamViec, string soDienThoaiLienHe, string maDoiTuong, string hoTenBo, int namSinhBo, string hoTenMe, int namSinhMe, string hoTenVoChong, int namSinhVoChong, string cao, string songMui, string tamVoc, string giongNoi, string nepTai, string daiTai, string mauDa, string dauVet, bool isDelete, int canBoQuanLyID, string maNhanKhau, string quanHeCanChuY)
		{
			DoiTuong entity = new DoiTuong();	
			entity.HoLot = hoLot;
			entity.Ten = ten;
			entity.TenGoiKhac = tenGoiKhac;
			entity.GioiTinh = gioiTinh;
			entity.NgaySinh = ngaySinh;
			entity.ThangSinh = thangSinh;
			entity.NamSinh = namSinh;
			entity.NoiSinh = noiSinh;
			entity.QueQuanTinhTPID = queQuanTinhTPID;
			entity.QueQuanQuanHuyenID = queQuanQuanHuyenID;
			entity.QueQuanXaPhuongID = queQuanXaPhuongID;
			entity.QueQuanToID = queQuanToID;
			entity.DanTocID = danTocID;
			entity.QuocTichID = quocTichID;
			entity.TonGiaoID = tonGiaoID;
			entity.SoCMND = soCMND;
			entity.NgayCapCMND = ngayCapCMND;
			entity.NoiCapCMND = noiCapCMND;
			entity.ThuongTruTinhTPID = thuongTruTinhTPID;
			entity.ThuongTruQuanHuyenID = thuongTruQuanHuyenID;
			entity.ThuongTruXaPhuongID = thuongTruXaPhuongID;
			entity.ThuongTruToID = thuongTruToID;
			entity.ThuongTruDiaChi = thuongTruDiaChi;
			entity.NoiOHienNayTinhTPID = noiOHienNayTinhTPID;
			entity.NoiOHienNayQuanHuyenID = noiOHienNayQuanHuyenID;
			entity.NoiOHienNayXaPhuongID = noiOHienNayXaPhuongID;
			entity.NoiOHienNayToID = noiOHienNayToID;
			entity.NoiOHienNayDiaChi = noiOHienNayDiaChi;
			entity.TrinhDoHocVanID = trinhDoHocVanID;
			entity.TrinhDoChuyenMonID = trinhDoChuyenMonID;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.SoDienThoaiLienHe = soDienThoaiLienHe;
			entity.MaDoiTuong = maDoiTuong;
			entity.HoTenBo = hoTenBo;
			entity.NamSinhBo = namSinhBo;
			entity.HoTenMe = hoTenMe;
			entity.NamSinhMe = namSinhMe;
			entity.HoTenVoChong = hoTenVoChong;
			entity.NamSinhVoChong = namSinhVoChong;
			entity.Cao = cao;
			entity.SongMui = songMui;
			entity.TamVoc = tamVoc;
			entity.GiongNoi = giongNoi;
			entity.NepTai = nepTai;
			entity.DaiTai = daiTai;
			entity.MauDa = mauDa;
			entity.DauVet = dauVet;
			entity.IsDelete = isDelete;
			entity.CanBoQuanLyID = canBoQuanLyID;
			entity.MaNhanKhau = maNhanKhau;
			entity.QuanHeCanChuY = quanHeCanChuY;
			return entity.Insert();
		}
		
		public long Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public long Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_DoiTuong_Insert.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddOutParameter(dbCommand, "@ID", SqlDbType.BigInt, 8);
			db.AddInParameter(dbCommand, "@HoLot", SqlDbType.NVarChar, HoLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@TenGoiKhac", SqlDbType.NVarChar, TenGoiKhac);
			db.AddInParameter(dbCommand, "@GioiTinh", SqlDbType.Int, GioiTinh);
			db.AddInParameter(dbCommand, "@NgaySinh", SqlDbType.Int, NgaySinh);
			db.AddInParameter(dbCommand, "@ThangSinh", SqlDbType.Int, ThangSinh);
			db.AddInParameter(dbCommand, "@NamSinh", SqlDbType.Int, NamSinh);
			db.AddInParameter(dbCommand, "@NoiSinh", SqlDbType.NVarChar, NoiSinh);
			db.AddInParameter(dbCommand, "@QueQuanTinhTPID", SqlDbType.Int, QueQuanTinhTPID);
			db.AddInParameter(dbCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, QueQuanQuanHuyenID);
			db.AddInParameter(dbCommand, "@QueQuanXaPhuongID", SqlDbType.Int, QueQuanXaPhuongID);
			db.AddInParameter(dbCommand, "@QueQuanToID", SqlDbType.Int, QueQuanToID);
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, DanTocID);
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, QuocTichID);
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, TonGiaoID);
			db.AddInParameter(dbCommand, "@SoCMND", SqlDbType.VarChar, SoCMND);
			db.AddInParameter(dbCommand, "@NgayCapCMND", SqlDbType.DateTime, NgayCapCMND.Year <= 1753 ? DBNull.Value : (object) NgayCapCMND);
			db.AddInParameter(dbCommand, "@NoiCapCMND", SqlDbType.NVarChar, NoiCapCMND);
			db.AddInParameter(dbCommand, "@ThuongTruTinhTPID", SqlDbType.Int, ThuongTruTinhTPID);
			db.AddInParameter(dbCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, ThuongTruQuanHuyenID);
			db.AddInParameter(dbCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, ThuongTruXaPhuongID);
			db.AddInParameter(dbCommand, "@ThuongTruToID", SqlDbType.Int, ThuongTruToID);
			db.AddInParameter(dbCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, ThuongTruDiaChi);
			db.AddInParameter(dbCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, NoiOHienNayTinhTPID);
			db.AddInParameter(dbCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, NoiOHienNayQuanHuyenID);
			db.AddInParameter(dbCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, NoiOHienNayXaPhuongID);
			db.AddInParameter(dbCommand, "@NoiOHienNayToID", SqlDbType.Int, NoiOHienNayToID);
			db.AddInParameter(dbCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, NoiOHienNayDiaChi);
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, TrinhDoHocVanID);
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, TrinhDoChuyenMonID);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, SoDienThoaiLienHe);
			db.AddInParameter(dbCommand, "@MaDoiTuong", SqlDbType.VarChar, MaDoiTuong);
			db.AddInParameter(dbCommand, "@HoTenBo", SqlDbType.NVarChar, HoTenBo);
			db.AddInParameter(dbCommand, "@NamSinhBo", SqlDbType.Int, NamSinhBo);
			db.AddInParameter(dbCommand, "@HoTenMe", SqlDbType.NVarChar, HoTenMe);
			db.AddInParameter(dbCommand, "@NamSinhMe", SqlDbType.Int, NamSinhMe);
			db.AddInParameter(dbCommand, "@HoTenVoChong", SqlDbType.NVarChar, HoTenVoChong);
			db.AddInParameter(dbCommand, "@NamSinhVoChong", SqlDbType.Int, NamSinhVoChong);
			db.AddInParameter(dbCommand, "@Cao", SqlDbType.NVarChar, Cao);
			db.AddInParameter(dbCommand, "@SongMui", SqlDbType.NVarChar, SongMui);
			db.AddInParameter(dbCommand, "@TamVoc", SqlDbType.NVarChar, TamVoc);
			db.AddInParameter(dbCommand, "@GiongNoi", SqlDbType.NVarChar, GiongNoi);
			db.AddInParameter(dbCommand, "@NepTai", SqlDbType.NVarChar, NepTai);
			db.AddInParameter(dbCommand, "@DaiTai", SqlDbType.NVarChar, DaiTai);
			db.AddInParameter(dbCommand, "@MauDa", SqlDbType.NVarChar, MauDa);
			db.AddInParameter(dbCommand, "@DauVet", SqlDbType.NVarChar, DauVet);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			db.AddInParameter(dbCommand, "@MaNhanKhau", SqlDbType.NVarChar, MaNhanKhau);
			db.AddInParameter(dbCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, QuanHeCanChuY);
			
			if (transaction != null)
			{
				db.ExecuteNonQuery(dbCommand, transaction);
				ID = (long) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}
            else
			{
				db.ExecuteNonQuery(dbCommand);
				ID = (long) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(List<DoiTuong> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateDoiTuong(long iD, string hoLot, string ten, string tenGoiKhac, int gioiTinh, int ngaySinh, int thangSinh, int namSinh, string noiSinh, int queQuanTinhTPID, int queQuanQuanHuyenID, int queQuanXaPhuongID, int queQuanToID, int danTocID, int quocTichID, int tonGiaoID, string soCMND, DateTime ngayCapCMND, string noiCapCMND, int thuongTruTinhTPID, int thuongTruQuanHuyenID, int thuongTruXaPhuongID, int thuongTruToID, string thuongTruDiaChi, int noiOHienNayTinhTPID, int noiOHienNayQuanHuyenID, int noiOHienNayXaPhuongID, int noiOHienNayToID, string noiOHienNayDiaChi, int trinhDoHocVanID, int trinhDoChuyenMonID, string ngheNghiepNoiLamViec, string soDienThoaiLienHe, string maDoiTuong, string hoTenBo, int namSinhBo, string hoTenMe, int namSinhMe, string hoTenVoChong, int namSinhVoChong, string cao, string songMui, string tamVoc, string giongNoi, string nepTai, string daiTai, string mauDa, string dauVet, bool isDelete, int canBoQuanLyID, string maNhanKhau, string quanHeCanChuY)
		{
			DoiTuong entity = new DoiTuong();			
			entity.ID = iD;
			entity.HoLot = hoLot;
			entity.Ten = ten;
			entity.TenGoiKhac = tenGoiKhac;
			entity.GioiTinh = gioiTinh;
			entity.NgaySinh = ngaySinh;
			entity.ThangSinh = thangSinh;
			entity.NamSinh = namSinh;
			entity.NoiSinh = noiSinh;
			entity.QueQuanTinhTPID = queQuanTinhTPID;
			entity.QueQuanQuanHuyenID = queQuanQuanHuyenID;
			entity.QueQuanXaPhuongID = queQuanXaPhuongID;
			entity.QueQuanToID = queQuanToID;
			entity.DanTocID = danTocID;
			entity.QuocTichID = quocTichID;
			entity.TonGiaoID = tonGiaoID;
			entity.SoCMND = soCMND;
			entity.NgayCapCMND = ngayCapCMND;
			entity.NoiCapCMND = noiCapCMND;
			entity.ThuongTruTinhTPID = thuongTruTinhTPID;
			entity.ThuongTruQuanHuyenID = thuongTruQuanHuyenID;
			entity.ThuongTruXaPhuongID = thuongTruXaPhuongID;
			entity.ThuongTruToID = thuongTruToID;
			entity.ThuongTruDiaChi = thuongTruDiaChi;
			entity.NoiOHienNayTinhTPID = noiOHienNayTinhTPID;
			entity.NoiOHienNayQuanHuyenID = noiOHienNayQuanHuyenID;
			entity.NoiOHienNayXaPhuongID = noiOHienNayXaPhuongID;
			entity.NoiOHienNayToID = noiOHienNayToID;
			entity.NoiOHienNayDiaChi = noiOHienNayDiaChi;
			entity.TrinhDoHocVanID = trinhDoHocVanID;
			entity.TrinhDoChuyenMonID = trinhDoChuyenMonID;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.SoDienThoaiLienHe = soDienThoaiLienHe;
			entity.MaDoiTuong = maDoiTuong;
			entity.HoTenBo = hoTenBo;
			entity.NamSinhBo = namSinhBo;
			entity.HoTenMe = hoTenMe;
			entity.NamSinhMe = namSinhMe;
			entity.HoTenVoChong = hoTenVoChong;
			entity.NamSinhVoChong = namSinhVoChong;
			entity.Cao = cao;
			entity.SongMui = songMui;
			entity.TamVoc = tamVoc;
			entity.GiongNoi = giongNoi;
			entity.NepTai = nepTai;
			entity.DaiTai = daiTai;
			entity.MauDa = mauDa;
			entity.DauVet = dauVet;
			entity.IsDelete = isDelete;
			entity.CanBoQuanLyID = canBoQuanLyID;
			entity.MaNhanKhau = maNhanKhau;
			entity.QuanHeCanChuY = quanHeCanChuY;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "[dbo].p_DoiTuong_InsertUpdate.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, ID);
			db.AddInParameter(dbCommand, "@HoLot", SqlDbType.NVarChar, HoLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@TenGoiKhac", SqlDbType.NVarChar, TenGoiKhac);
			db.AddInParameter(dbCommand, "@GioiTinh", SqlDbType.Int, GioiTinh);
			db.AddInParameter(dbCommand, "@NgaySinh", SqlDbType.Int, NgaySinh);
			db.AddInParameter(dbCommand, "@ThangSinh", SqlDbType.Int, ThangSinh);
			db.AddInParameter(dbCommand, "@NamSinh", SqlDbType.Int, NamSinh);
			db.AddInParameter(dbCommand, "@NoiSinh", SqlDbType.NVarChar, NoiSinh);
			db.AddInParameter(dbCommand, "@QueQuanTinhTPID", SqlDbType.Int, QueQuanTinhTPID);
			db.AddInParameter(dbCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, QueQuanQuanHuyenID);
			db.AddInParameter(dbCommand, "@QueQuanXaPhuongID", SqlDbType.Int, QueQuanXaPhuongID);
			db.AddInParameter(dbCommand, "@QueQuanToID", SqlDbType.Int, QueQuanToID);
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, DanTocID);
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, QuocTichID);
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, TonGiaoID);
			db.AddInParameter(dbCommand, "@SoCMND", SqlDbType.VarChar, SoCMND);
			db.AddInParameter(dbCommand, "@NgayCapCMND", SqlDbType.DateTime, NgayCapCMND.Year <= 1753 ? DBNull.Value : (object) NgayCapCMND);
			db.AddInParameter(dbCommand, "@NoiCapCMND", SqlDbType.NVarChar, NoiCapCMND);
			db.AddInParameter(dbCommand, "@ThuongTruTinhTPID", SqlDbType.Int, ThuongTruTinhTPID);
			db.AddInParameter(dbCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, ThuongTruQuanHuyenID);
			db.AddInParameter(dbCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, ThuongTruXaPhuongID);
			db.AddInParameter(dbCommand, "@ThuongTruToID", SqlDbType.Int, ThuongTruToID);
			db.AddInParameter(dbCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, ThuongTruDiaChi);
			db.AddInParameter(dbCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, NoiOHienNayTinhTPID);
			db.AddInParameter(dbCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, NoiOHienNayQuanHuyenID);
			db.AddInParameter(dbCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, NoiOHienNayXaPhuongID);
			db.AddInParameter(dbCommand, "@NoiOHienNayToID", SqlDbType.Int, NoiOHienNayToID);
			db.AddInParameter(dbCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, NoiOHienNayDiaChi);
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, TrinhDoHocVanID);
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, TrinhDoChuyenMonID);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, SoDienThoaiLienHe);
			db.AddInParameter(dbCommand, "@MaDoiTuong", SqlDbType.VarChar, MaDoiTuong);
			db.AddInParameter(dbCommand, "@HoTenBo", SqlDbType.NVarChar, HoTenBo);
			db.AddInParameter(dbCommand, "@NamSinhBo", SqlDbType.Int, NamSinhBo);
			db.AddInParameter(dbCommand, "@HoTenMe", SqlDbType.NVarChar, HoTenMe);
			db.AddInParameter(dbCommand, "@NamSinhMe", SqlDbType.Int, NamSinhMe);
			db.AddInParameter(dbCommand, "@HoTenVoChong", SqlDbType.NVarChar, HoTenVoChong);
			db.AddInParameter(dbCommand, "@NamSinhVoChong", SqlDbType.Int, NamSinhVoChong);
			db.AddInParameter(dbCommand, "@Cao", SqlDbType.NVarChar, Cao);
			db.AddInParameter(dbCommand, "@SongMui", SqlDbType.NVarChar, SongMui);
			db.AddInParameter(dbCommand, "@TamVoc", SqlDbType.NVarChar, TamVoc);
			db.AddInParameter(dbCommand, "@GiongNoi", SqlDbType.NVarChar, GiongNoi);
			db.AddInParameter(dbCommand, "@NepTai", SqlDbType.NVarChar, NepTai);
			db.AddInParameter(dbCommand, "@DaiTai", SqlDbType.NVarChar, DaiTai);
			db.AddInParameter(dbCommand, "@MauDa", SqlDbType.NVarChar, MauDa);
			db.AddInParameter(dbCommand, "@DauVet", SqlDbType.NVarChar, DauVet);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			db.AddInParameter(dbCommand, "@MaNhanKhau", SqlDbType.NVarChar, MaNhanKhau);
			db.AddInParameter(dbCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, QuanHeCanChuY);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(List<DoiTuong> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateDoiTuong(long iD, string hoLot, string ten, string tenGoiKhac, int gioiTinh, int ngaySinh, int thangSinh, int namSinh, string noiSinh, int queQuanTinhTPID, int queQuanQuanHuyenID, int queQuanXaPhuongID, int queQuanToID, int danTocID, int quocTichID, int tonGiaoID, string soCMND, DateTime ngayCapCMND, string noiCapCMND, int thuongTruTinhTPID, int thuongTruQuanHuyenID, int thuongTruXaPhuongID, int thuongTruToID, string thuongTruDiaChi, int noiOHienNayTinhTPID, int noiOHienNayQuanHuyenID, int noiOHienNayXaPhuongID, int noiOHienNayToID, string noiOHienNayDiaChi, int trinhDoHocVanID, int trinhDoChuyenMonID, string ngheNghiepNoiLamViec, string soDienThoaiLienHe, string maDoiTuong, string hoTenBo, int namSinhBo, string hoTenMe, int namSinhMe, string hoTenVoChong, int namSinhVoChong, string cao, string songMui, string tamVoc, string giongNoi, string nepTai, string daiTai, string mauDa, string dauVet, bool isDelete, int canBoQuanLyID, string maNhanKhau, string quanHeCanChuY)
		{
			DoiTuong entity = new DoiTuong();			
			entity.ID = iD;
			entity.HoLot = hoLot;
			entity.Ten = ten;
			entity.TenGoiKhac = tenGoiKhac;
			entity.GioiTinh = gioiTinh;
			entity.NgaySinh = ngaySinh;
			entity.ThangSinh = thangSinh;
			entity.NamSinh = namSinh;
			entity.NoiSinh = noiSinh;
			entity.QueQuanTinhTPID = queQuanTinhTPID;
			entity.QueQuanQuanHuyenID = queQuanQuanHuyenID;
			entity.QueQuanXaPhuongID = queQuanXaPhuongID;
			entity.QueQuanToID = queQuanToID;
			entity.DanTocID = danTocID;
			entity.QuocTichID = quocTichID;
			entity.TonGiaoID = tonGiaoID;
			entity.SoCMND = soCMND;
			entity.NgayCapCMND = ngayCapCMND;
			entity.NoiCapCMND = noiCapCMND;
			entity.ThuongTruTinhTPID = thuongTruTinhTPID;
			entity.ThuongTruQuanHuyenID = thuongTruQuanHuyenID;
			entity.ThuongTruXaPhuongID = thuongTruXaPhuongID;
			entity.ThuongTruToID = thuongTruToID;
			entity.ThuongTruDiaChi = thuongTruDiaChi;
			entity.NoiOHienNayTinhTPID = noiOHienNayTinhTPID;
			entity.NoiOHienNayQuanHuyenID = noiOHienNayQuanHuyenID;
			entity.NoiOHienNayXaPhuongID = noiOHienNayXaPhuongID;
			entity.NoiOHienNayToID = noiOHienNayToID;
			entity.NoiOHienNayDiaChi = noiOHienNayDiaChi;
			entity.TrinhDoHocVanID = trinhDoHocVanID;
			entity.TrinhDoChuyenMonID = trinhDoChuyenMonID;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.SoDienThoaiLienHe = soDienThoaiLienHe;
			entity.MaDoiTuong = maDoiTuong;
			entity.HoTenBo = hoTenBo;
			entity.NamSinhBo = namSinhBo;
			entity.HoTenMe = hoTenMe;
			entity.NamSinhMe = namSinhMe;
			entity.HoTenVoChong = hoTenVoChong;
			entity.NamSinhVoChong = namSinhVoChong;
			entity.Cao = cao;
			entity.SongMui = songMui;
			entity.TamVoc = tamVoc;
			entity.GiongNoi = giongNoi;
			entity.NepTai = nepTai;
			entity.DaiTai = daiTai;
			entity.MauDa = mauDa;
			entity.DauVet = dauVet;
			entity.IsDelete = isDelete;
			entity.CanBoQuanLyID = canBoQuanLyID;
			entity.MaNhanKhau = maNhanKhau;
			entity.QuanHeCanChuY = quanHeCanChuY;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_DoiTuong_Update.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, ID);
			db.AddInParameter(dbCommand, "@HoLot", SqlDbType.NVarChar, HoLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@TenGoiKhac", SqlDbType.NVarChar, TenGoiKhac);
			db.AddInParameter(dbCommand, "@GioiTinh", SqlDbType.Int, GioiTinh);
			db.AddInParameter(dbCommand, "@NgaySinh", SqlDbType.Int, NgaySinh);
			db.AddInParameter(dbCommand, "@ThangSinh", SqlDbType.Int, ThangSinh);
			db.AddInParameter(dbCommand, "@NamSinh", SqlDbType.Int, NamSinh);
			db.AddInParameter(dbCommand, "@NoiSinh", SqlDbType.NVarChar, NoiSinh);
			db.AddInParameter(dbCommand, "@QueQuanTinhTPID", SqlDbType.Int, QueQuanTinhTPID);
			db.AddInParameter(dbCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, QueQuanQuanHuyenID);
			db.AddInParameter(dbCommand, "@QueQuanXaPhuongID", SqlDbType.Int, QueQuanXaPhuongID);
			db.AddInParameter(dbCommand, "@QueQuanToID", SqlDbType.Int, QueQuanToID);
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, DanTocID);
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, QuocTichID);
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, TonGiaoID);
			db.AddInParameter(dbCommand, "@SoCMND", SqlDbType.VarChar, SoCMND);
			db.AddInParameter(dbCommand, "@NgayCapCMND", SqlDbType.DateTime, NgayCapCMND.Year <= 1753 ? DBNull.Value : (object) NgayCapCMND);
			db.AddInParameter(dbCommand, "@NoiCapCMND", SqlDbType.NVarChar, NoiCapCMND);
			db.AddInParameter(dbCommand, "@ThuongTruTinhTPID", SqlDbType.Int, ThuongTruTinhTPID);
			db.AddInParameter(dbCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, ThuongTruQuanHuyenID);
			db.AddInParameter(dbCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, ThuongTruXaPhuongID);
			db.AddInParameter(dbCommand, "@ThuongTruToID", SqlDbType.Int, ThuongTruToID);
			db.AddInParameter(dbCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, ThuongTruDiaChi);
			db.AddInParameter(dbCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, NoiOHienNayTinhTPID);
			db.AddInParameter(dbCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, NoiOHienNayQuanHuyenID);
			db.AddInParameter(dbCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, NoiOHienNayXaPhuongID);
			db.AddInParameter(dbCommand, "@NoiOHienNayToID", SqlDbType.Int, NoiOHienNayToID);
			db.AddInParameter(dbCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, NoiOHienNayDiaChi);
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, TrinhDoHocVanID);
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, TrinhDoChuyenMonID);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, SoDienThoaiLienHe);
			db.AddInParameter(dbCommand, "@MaDoiTuong", SqlDbType.VarChar, MaDoiTuong);
			db.AddInParameter(dbCommand, "@HoTenBo", SqlDbType.NVarChar, HoTenBo);
			db.AddInParameter(dbCommand, "@NamSinhBo", SqlDbType.Int, NamSinhBo);
			db.AddInParameter(dbCommand, "@HoTenMe", SqlDbType.NVarChar, HoTenMe);
			db.AddInParameter(dbCommand, "@NamSinhMe", SqlDbType.Int, NamSinhMe);
			db.AddInParameter(dbCommand, "@HoTenVoChong", SqlDbType.NVarChar, HoTenVoChong);
			db.AddInParameter(dbCommand, "@NamSinhVoChong", SqlDbType.Int, NamSinhVoChong);
			db.AddInParameter(dbCommand, "@Cao", SqlDbType.NVarChar, Cao);
			db.AddInParameter(dbCommand, "@SongMui", SqlDbType.NVarChar, SongMui);
			db.AddInParameter(dbCommand, "@TamVoc", SqlDbType.NVarChar, TamVoc);
			db.AddInParameter(dbCommand, "@GiongNoi", SqlDbType.NVarChar, GiongNoi);
			db.AddInParameter(dbCommand, "@NepTai", SqlDbType.NVarChar, NepTai);
			db.AddInParameter(dbCommand, "@DaiTai", SqlDbType.NVarChar, DaiTai);
			db.AddInParameter(dbCommand, "@MauDa", SqlDbType.NVarChar, MauDa);
			db.AddInParameter(dbCommand, "@DauVet", SqlDbType.NVarChar, DauVet);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			db.AddInParameter(dbCommand, "@MaNhanKhau", SqlDbType.NVarChar, MaNhanKhau);
			db.AddInParameter(dbCommand, "@QuanHeCanChuY", SqlDbType.NVarChar, QuanHeCanChuY);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(List<DoiTuong> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteDoiTuong(long iD)
		{
			DoiTuong entity = new DoiTuong();
			entity.ID = iD;
			
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_DoiTuong_Delete.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, ID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		
		public static int DeleteDynamic(string whereCondition)
		{
			const string spName = "[dbo].[p_DoiTuong_DeleteDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            
            return db.ExecuteNonQuery(dbCommand);   
		}
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(List<DoiTuong> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (DoiTuong item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
		
        //---------------------------------------------------------------------------------------------
		
        #region ICloneable Members

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        public DoiTuong CloneObject()
        {
            return this.Clone() as DoiTuong;
        }
        
        #endregion
	}	
}